<template>
  <div>
    <router-view/>
  </div>
</template>

<script>
import {config} from "@/common/WebIMConfig";
import {Dialog, Toast} from "vant";

export default {
  data() {
    return {}
  },
  created() {
      this.initConn()
  },
  mounted() {

  },
  methods: {
    // 初始化链接监听
    initConn() {
      const _this = this
      this.WebIm.conn.listen({
        onTextMessage: function (message) {
          // 如果是给当前聊天用户发消息，则添加到msgList
          if (_this.friendPhone == message.from) {
            _this.msgList.push({isMe: false, text: message.data, id: message.serverMsgId})
          }
          //存储消息到本地
          let localMsg = localStorage.getItem(message.to + "-" + message.from);
          let msgList = []
          if (localMsg) {
            msgList = JSON.parse(localMsg)
          }
          msgList.push({isMe: false, text: message.data, id: message.id})
          localStorage.setItem(message.to + "-" + message.from, JSON.stringify(msgList))
        }
      })
    },
  },
  component: {}
}
</script>

<style scoped>

</style>
